<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目编号" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目部门" prop="projectDeptId">
        <treeselect v-model="queryParams.projectDeptId" :options="deptList" :show-count="true" placeholder="请选择归属部门" style="width: 200px"/>
      </el-form-item>
      <el-form-item label="资质主体" prop="projectAgencyId">
        <el-select v-model="queryParams.projectAgencyId"  clearable placeholder="请选择" >
          <el-option
            v-for="item in projectagencyList"
            :key="item.id"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

      <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
        <el-table-column type="selection"  align="center" />
        <el-table-column label="ID" width="40" align="center" prop="id" />
        <el-table-column label="项目名称" align="center" prop="projectName" />
        <el-table-column label="项目编号" align="center" prop="projectCode" />
        <el-table-column label="所属部门" align="center" prop="projectDeptName" />
        <el-table-column label="类型方式" align="center" prop="projectTypeName" />
        <el-table-column label="项目流程" align="center" prop="projectBidevaluationProcessName" />
        <el-table-column label="委托单位" align="center" prop="projectTenderee" />
        <el-table-column label="预算(万)" align="center"  >
          <template slot-scope="scope" >
            {{scope.row.projectBudget/10000}}
          </template>
        </el-table-column>
        <el-table-column label="资质主体" align="center" prop="projectAgencyName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleSelect(scope.row)"
          >选择</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listProject } from "@/api/system/project";
import Treeselect from "@riophae/vue-treeselect";
import {listsCompany} from "@/api/system/company";
import {deptTreeSelect} from "@/api/system/user";

export default {
  components: {Treeselect},
  props:['getProjectRow'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招标人管理表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      // 资质主体
      projectagencyList: [],
      // 部门列表
      deptList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectCode: null,
        projectExternaltCode: null,
        projectTypeId: null,
        projectTypeName: null,
        projectTenderModeId: null,
        projectTenderModeName: null,
        projectBudget: null,
        projectRxpectedIncome: null,
        projectTendererId: null,
        projectTendererName: null,
        projectLeaderId: null,
        projectLeader: null,
        projectOperatorId: null,
        projectOperator: null,
        projectImplementAreaId: null,
        projectImplementArea: null,
        projectDeptId: null,
        projectDeptName: null,
        projectAreaId: null,
        projectAreaName: null,
        projectAgencyId: null,
        projectAgencyName: null,
        approvalStatus: null,
        projectStatus: null,
        projectBidevaluationModeId: null,
        projectBidevaluationModeName: null,
        projectBidevaluationProcessId: null,
        projectBidevaluationProcessName: null,
        projectFundingSourceId: null,
        projectFundingSourceName: null,
        projectPayerId: null,
        projectPayerName: null,
        projectDeveloperId: null,
        projectDeveloper: null,
        projectDescription: null,
        projectRemark: null,
        attachmentSrc: null,
        projectTendereeId: null,
        projectTenderee: null,
        projectTendereeContactPerson: null,
        projectTendereeContactTel: null,
        sort: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getListsCompany();
    this.getDeptTree();
  },
  methods: {
    /** 查询招标人管理列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListsCompany() {
      this.loading = true;
      listsCompany(this.queryParams).then(response => {
        this.projectagencyList = response.data;
        this.loading = false;
      });

    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptList = response.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleSelect(row){
      this.getProjectRow(row);
    }
  }
};
</script>
